//
//  ResultSummaryViewController.m
//  Surveyer
//
//  Created by Tim on 13-8-21.
//  Copyright (c) 2013年 Tim. All rights reserved.
//

#import "ResultSummaryViewController.h"
#import <ShareSDK/ShareSDK.h>

@interface ResultSummaryViewController ()
@property (weak, nonatomic) IBOutlet UIScrollView *scrollView;
@property (strong, nonatomic) IBOutlet UIView *targetView;
@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
@property (weak, nonatomic) IBOutlet UILabel *questionCount;
@property (weak, nonatomic) IBOutlet UILabel *lastModified;
@property (weak, nonatomic) IBOutlet UILabel *introLabel;
@property (weak, nonatomic) IBOutlet UILabel *responseNo;
@property (weak, nonatomic) IBOutlet UILabel *swipe2see;

@end

@implementation ResultSummaryViewController
@synthesize currentSurvey, scrollView, targetView;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        formatter = [[NSDateFormatter alloc] init];
        formatter.dateStyle=NSDateFormatterMediumStyle;
        formatter.timeStyle=NSDateFormatterNoStyle;
        [formatter setLocale:[NSLocale currentLocale]];
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    //general code
    [scrollView addSubview:targetView];
    [scrollView setContentSize:targetView.frame.size];
    [scrollView setScrollEnabled:YES];
    
    //static
    self.titleLabel.textColor = RESULT_COLOR;
    self.swipe2see.text = NSLocalizedString(@"Swipe to see detail information", @"result view");
    outputString = [currentSurvey textOutput];
    
    //dynamic
    self.titleLabel.text = [NSLocalizedString(@"Result of Survey" , @"title in Result view") stringByAppendingFormat:@"\"%@\"",currentSurvey.title];
    self.questionCount.text = [NSLocalizedString(@"Number of questions: ", @"text in resultSummary") stringByAppendingFormat:@"%d", currentSurvey.items.count];
    NSDate *date = [NSDate dateWithTimeIntervalSince1970:currentSurvey.modifiedDate];
    self.lastModified.text = [NSLocalizedString(@"Last Modified: ", @"text in resultView") stringByAppendingString:[formatter stringFromDate:date]];
    self.introLabel.text = currentSurvey.intro;
    self.responseNo.text = [NSString stringWithFormat:@"%d %@", currentSurvey.time, NSLocalizedString(@"responses completed", @"result view")];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)mail:(id)sender {
    [[SurveyerStore defaultStore] mailSurvey:currentSurvey WithDelegate:self];
}

- (IBAction)share:(id)sender {
#warning share not implemented
    [[SurveyerStore defaultStore] shareSurvey:currentSurvey ByType:ShareTypeSinaWeibo];
}

@end
